/*
 * @Author: yixin
 * @Date: 2018-06-22 11:30:27
 * @Last Modified by: yixin
 * @Last Modified time: 2018-07-22 20:26:53
 */
import { Navigation } from 'react-native-navigation';
import { registerScreens } from './screen';
import { initIcons } from './utils/Icons';
import clog from './utils/log';
import { reduxStore } from './controllers';
import registerEvent from './utils/appEvent';

export default class App {
  constructor() {
    // 注册reduxStore
    reduxStore({}, Store => {
      // 注册页面
      registerScreens(Store);
      registerEvent(Store);
      // tab初始化
      initIcons()
        .then(res => {
          this.toMain(res);
          // this.toTest()
        })
        .catch(err => {
          clog.info('APP 启动错误', err);
        });
      // 友盟推送添加tag
    });
  }

  toTest() {
    Navigation.startSingleScreenApp({
      screen: {
        screen: 'Details',
        title: '我的订单'
      }
    });
  }

  toMain(iconsMap) {
    Navigation.startTabBasedApp({
      tabs: [
        {
          label: '市场',
          screen: 'MarketScreen',
          icon: iconsMap['market_n'],
          selectedIcon: iconsMap['market_h'], // iOS only
          title: '市场'
        },
        {
          label: '众筹',
          screen: 'IcoScreen', // this is a registered name for a screen
          icon: iconsMap['zc_n'],
          selectedIcon: iconsMap['zc_h'], // iOS only
          title: '众筹'
        },
        {
          label: '我的',
          screen: 'MyScreen', // this is a registered name for a screen
          icon: iconsMap['my_n'],
          selectedIcon: iconsMap['my_h'], // iOS only
          title: '我的'
        },
      ],
      tabsStyle: { // optional, add this if you want to style the tab bar beyond the defaults
        // tabBarButtonColor: '#f5f5f5', // optional, change the color of the tab icons and text (also unselected). On Android, add this to appStyle
        tabBarSelectedButtonColor: '#FEC31D', // optional, change the color of the selected tab icon and text (only selected). On Android, add this to appStyle
        // tabBarBackgroundColor: '#551A8B', // optional, change the background color of the tab bar
        initialTabIndex: 0, // optional, the default selected bottom tab. Default: 0. On Android, add this to appStyle
      },
    //   animationType: 'slide-down' // optional, add transition animation to root change: 'none', 'slide-down', 'fade'
    });
  }
}
